package com.lcxw.hxzbadmin.scheduleTask;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import java.util.List;
import javax.annotation.Resource;
import com.lcxw.hxzbadmin.entity.ranklist.RoomRankBean;
import com.lcxw.hxzbcommon.common.RedisUtils;

//@Component
public class RoomDayRangeTask {

    @Resource
    RedisUtils redisUtils;

//    @Scheduled(cron = "3/10 * * * * *") //每天凌晨0点0分30秒开始执行，30秒是为了防止跟其他任务时间冲突。
//    @Scheduled(cron = "30 0 0 * * *") //每天凌晨0点0分30秒开始执行，30秒是为了防止跟其他任务时间冲突。
    public void dayCount() {
        String redisKey = "roomEarn:Range:month";

        String redisKey_video = "roomRange:video";
        String redisKey_fullVideo = "roomRange:fullVideo";
        String redisKey_voice = "roomRange:voice";

        redisUtils.list_delete(redisKey_video);
        redisUtils.list_delete(redisKey_fullVideo);
        redisUtils.list_delete(redisKey_voice);

        List list = redisUtils.list_range(redisKey);

        List<RoomRankBean> roomRankBeans = JSON.parseArray(list.toString(),RoomRankBean.class);

        for (RoomRankBean roomRankBean: roomRankBeans
        ) {
            String roomType = roomRankBean.getRoomType();

            if ("video".equals(roomType) || "fullVideo".equals(roomType)){
                redisUtils.list_rightPush(redisKey_video, JSONObject.toJSONString(roomRankBean));
            }else {
                redisUtils.list_rightPush(redisKey_voice, JSONObject.toJSONString(roomRankBean));
            }
        }
    }
}
